package com.linwen.javase.juc.threadPool;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @ClassName _03CompleteFuture
 * @Description
 * @Author lin
 * @Date 2022/4/25 上午12:03
 * @Version V1.0
 */
public class _03CompleteFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Void> voidCompletableFuture = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "  working");
        });
         voidCompletableFuture.get();

        CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + "  working");
            return 1024;
        });
        integerCompletableFuture.whenComplete((v,e)->{
            System.out.println("返回值为："+v);
            System.out.println("异常信息为："+e);
        });
        System.out.println(integerCompletableFuture.get());

    }
}
